package main

import (
	"log"
	"os"

	"github.com/valyala/fasthttp"
	"gopkg.in/alecthomas/kingpin.v2"
)

var (
	dbname   = kingpin.Flag("db", "database name").Default("bolt.db").String()
	basepath = kingpin.Flag("path", "base path").Default(".").String()
	port     = kingpin.Flag("port", "port to listen").Default("8888").Short('p').String()
	addr     = kingpin.Flag("addr", "addr to listen").Default("").Short('a').String()
	logfile  = kingpin.Flag("log", "log file").Default("bolt.log").Short('l').String()
)

func main() {
	kingpin.Parse()
	f, err := os.OpenFile(*logfile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()
	log.SetOutput(f)
	srv := Server{basePath: *basepath}
	srv.Setup()
	fasthttp.ListenAndServe(*addr+":"+*port, srv.Handle)
}
